// 选择器默认自定义options
export const fieldNames = {
  value: "id",
  label: "label",
  children: "children",
};
export const config = [
  {
    type: "input",
    component: "el-input",
    config: "inputConfig",
  },
  {
    type: "number",
    component: "el-input-number",
    config: "numberConfig",
    controlsPosition: "right",
  },
  {
    type: "textarea",
    component: "el-input",
    config: "inputConfig",
    autosize: true,
    // autosize: { minRows: 2, maxRows: 4 }
  },
  {
    type: "select",
    component: "el-select",
    config: "selectConfig",
    // filterable: true, // 是否可搜索
    fieldNames,
  },
  {
    type: "cascader",
    component: "el-cascader",
    config: "selectConfig",
    filterable: true,
    props: { ...fieldNames },
  },
  // 日期选择器一下类型如下
  {
    type: "date",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM-dd",
    valueFormat: "yyyy-MM-dd",
  },
  {
    type: "year",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy年",
    valueFormat: "yyyy",
  },
  {
    type: "month",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM",
    valueFormat: "yyyy-MM",
  },
  {
    type: "datetime",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM-dd HH:mm:ss",
    valueFormat: "yyyy-MM-dd HH:mm:ss",
  },
  {
    type: "week",
    component: "el-date-picker",
    config: "dateConfig",
    format: "WW 周",
  },
  // 日期多选
  {
    type: "dates",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM-dd",
    valueFormat: "yyyy-MM-dd",
  },
  // 以下日期区间选择器
  {
    type: "daterange",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM-dd",
    valueFormat: "yyyy-MM-dd",
  },
  {
    type: "datetimerange",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM-dd HH:mm:ss",
    valueFormat: "yyyy-MM-dd HH:mm:ss",
  },
  {
    type: "monthrange",
    component: "el-date-picker",
    config: "dateConfig",
    format: "yyyy-MM",
    valueFormat: "yyyy-MM",
  },
];
// props：父组件传入的参数配置
export const propsConfig = {
  // 组件统一大小
  size: { type: String, default: "small" },
  // 表单配置
  formParam: { type: Object, required: true, default: () => ({}) },
  formConfig: { type: Object, default: () => ({}) },
  /**
   * 选择器options，具体看demo
   * 父组件使用<v-table :optionConfig="{selectOptions: []}"/>
   */
  optionConfig: { type: Object, default: () => ({}) },
  // 根据条件禁用表单的集合对象，根据propList数组disabled是字符串条件返回，
  /**
   * 父组件使用<v-table :disabledConfig="{name:userId, address:userId == 1}"/>
   * disabledKeys：需要对比当前行的字段
   */
  disabledConfig: { type: Object, default: () => ({}) },
  // elementPlus 输入框/选择器默认配置，具体看elementPlus官网，可不使用
  inputConfig: { type: Object, default: () => ({}) },
  numberConfig: { type: Object, default: () => ({}) },
  selectConfig: { type: Object, default: () => ({}) },
  dateConfig: { type: Object, default: () => ({}) },
};

/**
 * data 为字符串时，通过 config 获取对应的配置
 * data 不满足条件时则返回本身
 */
export const findConfig = (data, config, type = "string") => {
  if (!data) return false;
  return typeof data === type ? config[data] : data;
};

// 效验规则提示
export const rulesMessage = {
  input: "请输入",
  textarea: "请输入",
  select: "请选择",
  tree: "请选择",
  cascader: "请选择",
  number: "请输入",
  date: "请选择",
  dates: "请选择",
  year: "请选择",
  month: "请选择",
  week: "请选择",
  datetime: "请选择",
};
